package main

import (
    "path/filepath"
    "log"
    "os"

    "github.com/therecipe/qt/core"
    "github.com/therecipe/qt/gui"
    "github.com/therecipe/qt/qml"
    "github.com/therecipe/qt/widgets"

    "notabug.org/jazzyeagle/IDEa/qmlgui"
    "notabug.org/jazzyeagle/IDEa/qtgui"
    "notabug.org/jazzyeagle/IDEa/lib"
)


func main() {
    log.Println("# of arguments: ", len(os.Args))

    lib.Connect()

    response := lib.GetShortcut(":o")
    log.Println("Shortcut :o = ", response)

    if len(os.Args) == 2 {
        switch os.Args[1] {
            case "--qml":
                log.Println("Qml")
                
                core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
                mainwindow := filepath.Join(os.Getenv("IDEa_QML"), "MainWindow.qml")
                gui.NewQGuiApplication(len(os.Args), os.Args)

                Engine := qml.NewQQmlApplicationEngine(nil)

                uiBridge := qmlgui.NewUIBridge(nil)
                uiBridge.LoadEngine(Engine)

                Engine.RootContext().SetContextProperty("uiBridge", uiBridge)
                Engine.Load(core.NewQUrl3(mainwindow, 0))

                gui.QGuiApplication_Exec()
            default:
                log.Println("Qt")
                idea := widgets.NewQApplication(len(os.Args), os.Args)
                window := qtgui.InitMainWindow()
                window.Show()
                idea.Exec()
        }
    } else {
        log.Println("Else")
        idea := widgets.NewQApplication(len(os.Args), os.Args)
        window := qtgui.InitMainWindow()
        window.Show()
        idea.Exec()
    }

    lib.Disconnect()
}
